home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01b.txt / 000170_icon-group-sender_Fri Nov 9 13:04:28 2001.msg < prev    next >
Internet Message Format  |  2002-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id fA9K3lc08843
  4.     for icon-group-addresses; Fri, 9 Nov 2001 13:03:47 -0700 (MST)
  5. Message-Id: <200111092003.fA9K3lc08843@baskerville.CS.Arizona.EDU>
  6. Date: Fri, 09 Nov 2001 08:45:33 -0700
  7. From: Steve Wampler <swampler@noao.edu>
  8. X-Accept-Language: en
  9. To: Taybin Rutkin <trutkin@physics.clarku.edu>, icon-group@cs.arizona.edu
  10. Subject: Re: mutual evaluation
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: RO
  13. Content-Length: 1737
  14.  
  15. Steve Wampler wrote, apparently w/o thinking:
  16. > The expression syntax:
  17. >     expr0(expr1,expr2,...,exprN)
  18. > has a couple of uses.  If expr0 evaluates to a function or procedure name
  19. > then that function/procedure is invoked (after evaluating the arguments
  20. > of course!).  If expr0 evaluates to an integer, then the arguments are
  21. > evaluated and the whole expression returns the result produced by the argument
  22. > in the position represented by that integer.  [Since expr0 evaluates to
  23. > a "position", 0 means to produce the result of the last argument and
  24. > omitting expr0 defaults it to 0.]
  25.  
  26. Sigh, as was kindly pointed out to me, the last sentence is simply wrong.
  27.  
  28. When expr0 produces an integer, that integer is treated as identifying
  29. the position of the argument whose value is to be produced.  As such it follows
  30. the same rules as other positions (e.g. lists and strings).  That means a value
  31. of 0 references a non-existant position "one-off" the end of the list of
  32. expressions.  So, omitting expr0 defaults to -1, not 0, and 0(expr1,expr2,expr3)
  33. is equivalent to
  34.  
  35.    expr1 & expr2 & expr3 & &fail
  36.  
  37. For example, the following program:
  38.  
  39.     procedure main(args)
  40.         every i := -3 to 3 do
  41.             write(i, ": ", i("a", "b", "c") | "failed")
  42.     end
  43.  
  44. outputs:
  45.  
  46.     -3: a
  47.     -2: b
  48.     -1: c
  49.     0: failed
  50.     1: a
  51.     2: b
  52.     3: c
  53.  
  54. Finally, if you want the result of the last expression, you can write
  55. either:
  56.  
  57.     (expr1, expr2, ...., exprN)
  58.  
  59. or
  60.  
  61.     (-1)(expr1, expr2, ...., exprN)
  62.  
  63. but
  64.  
  65.     -1(expr1, expr2, ...., exprN)
  66.  
  67. won't work as you might expect, because of precedence rules.
  68.  
  69. My thanks to Steve Hunter for catching this!
  70.  
  71.  
  72.  
  73.  
  74.  
  75. --
  76. Steve Wampler-  SOLIS Project, National Solar Observatory
  77. swampler@noao.edu
  78.